define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'canguan/index' + location.search,
                    edit_url: 'canguan/edit',
                    table: 'visiting',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                searchFormVisible: true,
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'users.name', title: __('Users.name')},
                        {field: 'name', title: __('Name')},
                        {field: 'mobile', title: __('Mobile')},
                        {field: 'venue', title: __('Venue')},
                        {field: 'company', title: __('Company')},
                        {field: 'department', title: __('Department')},
                        {field: 'position_type', title: __('Position_type')},
                        {field: 'views', title: __('Views')},
                        {field: 'actual_views', title: __('Actual_views')},
                        {field: 'explain', title: __('是否需要讲解服务'),searchList: {"1": __('不需要'),"0": __('需要')}},
                        {field: 'day', title: __('Day')},
                        {field: 'between_time', title: __('Between_time'),searchList: {"0": __('9:00-10:00'),"1": __('10:00-11:00'),"2": __('11:00-12:00'),"3": __('12:00-13:00'),"4": __('13:00-14:00'),"5": __('14:00-15:00'),"6": __('15:00-16:00')}},
                        {field: 'between_day', title: __('Between_day'),operate:false},
                        {field: 'status', title: __('预约状态'),searchList: {"0": __('等待预留'), "1": __('预约中'), "2": __('完成预约'), "3": __('取消预约'), "4": __('完成评价'), "5": __('特殊预留')}},
                        {field: 'note', title: __('Note')},
                        // {field: 'reason', title: __('Reason')},
                        {field: 'add_time', title: __('Add_time'),operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});